const { Controller } = require('egg');
const { ctxBodyFormatter } = require('../util/formatter');

class ExperimentScoreController extends Controller {
  async index() {
    const { ctx, service } = this;
    const res = ctxBodyFormatter(await service.experimentScore.getAllExperimentScore());
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async show() {
    const { ctx, service } = this;
    const experimentScore = ctx.params;
    const res = ctxBodyFormatter(await service.experimentScore.getExperimentScore(experimentScore));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async create() {
    const { ctx, service } = this;
    const experimentScore = ctx.request.body;
    const res = ctxBodyFormatter(await service.experimentScore.appendExperimentScore(experimentScore));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async update() {
    const { ctx, service } = this;
    const experimentScore = ctx.request.body;
    const res = ctxBodyFormatter(await service.experimentScore.updateExperimentScore(experimentScore));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async destroy() {
    const { ctx, service } = this;
    const experimentScore = ctx.params;
    const res = ctxBodyFormatter(await service.experimentScore.destroyExperimentScore(experimentScore));
    ctx.status = res.status;
    ctx.body = res.body;
  }
}

module.exports = ExperimentScoreController;
